package personal.zq.practice.common.utils;

import com.alibaba.excel.metadata.Head;
import com.alibaba.excel.write.merge.AbstractMergeStrategy;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.CellStyle;
import org.apache.poi.ss.usermodel.Font;
import org.apache.poi.ss.usermodel.IndexedColors;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.ss.util.CellRangeAddress;


public class BizMergeStrategy extends AbstractMergeStrategy {

    private int lastRow;
    private Sheet sheet;

    public BizMergeStrategy(int lastRow) {
        this.lastRow = lastRow;
    }

    @Override
    protected void merge(Sheet sheet, Cell cell, Head head, Integer integer) {
        this.sheet = sheet;
        if (cell.getRowIndex() == 2 && cell.getColumnIndex() == 0) {


            sheet.addMergedRegionUnsafe(new CellRangeAddress(2, 2
                    , 0, lastRow - 1));

            Workbook workbook = sheet.getWorkbook();
            CellStyle cellStyle = workbook.createCellStyle();
            Font cellFont = workbook.createFont();
            cellFont.setBold(true);
            cellFont.setColor(IndexedColors.RED.getIndex());
            cellStyle.setFont(cellFont);
            cell.setCellStyle(cellStyle);

        }
    }
}
